// pages/quit/quit.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    did:0,
    dname: ['财务部', '销售部', '开发部', '人事部', '后勤部'],
  },
  DnameChange(e) {
    this.setData({
      did: e.detail.value
    })
    var deptno = Number(this.data.did) + 1;
    this.GetInfo(deptno)

  },

  EnameChange(e) {
    this.setData({
      id: e.detail.value
    })
  },
  EmpnoChange(e) {
    this.setData({
      id: e.detail.value
    })
  },

  GetInfo(deptno){
    var that = this;
    wx.request({
      url: 'http://192.168.1.6:8080/WeChatJSON//getEnameGroupDept',
      data: {
        deptno: deptno
      }, method: 'GET',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res)
        var empno = [];var ename = [];
        for(var i = 0;i<res.data.length;i++){
          empno.push(res.data[i].empno)
          ename.push(res.data[i].ename)
        }
        that.setData({
          empno:empno,
          ename:ename,
          id:0
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.GetInfo(this.data.did + 1)
  },

  forsubmit:function(e){
    var reason = e.detail.value.reason;
    var empno = this.data.empno[this.data.id];
    var ename = this.data.ename[this.data.id];
    var deptno = Number(this.data.did) + 1;
    if (reason == ""){
      wx.showToast({
        title: '原因不能为空',
        icon: 'none'
      })
    }else{
      var that = this
      wx.request({
        url: 'http://192.168.1.6:8080/WeChatJSON//deleteEmp',
        data: {
          empno:empno,
          ename: ename,
          deptno:deptno,
          reason: reason
        }, method: 'GET',
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          console.log(res)
          if (res.data == "离职成功") {
            wx.showToast({
              title: '手续办理成功',
              icon: 'success'
            })
            setTimeout(function () {
              wx.navigateBack({
              })
            }, 1500)
          } else {
            wx.showToast({
              title: res.data,
              icon: 'none'
            })
          }
        }
      })
    }
  }
})